home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- static int sintblc[65]={
- 0,
- 804,
- 1607,
- 2410,
- 3211,
- 4011,
- 4807,
- 5601,
- 6392,
- 7179,
- 7961,
- 8739,
- 9511,
- 10278,
- 11038,
- 11792,
- 12539,
- 13278,
- 14009,
- 14732,
- 15446,
- 16150,
- 16845,
- 17530,
- 18204,
- 18867,
- 19519,
- 20159,
- 20787,
- 21402,
- 22004,
- 22594,
- 23169,
- 23731,
- 24278,
- 24811,
- 25329,
- 25831,
- 26318,
- 26789,
- 27244,
- 27683,
- 28105,
- 28510,
- 28897,
- 29268,
- 29621,
- 29955,
- 30272,
- 30571,
- 30851,
- 31113,
- 31356,
- 31580,
- 31785,
- 31970,
- 32137,
- 32284,
- 32412,
- 32520,
- 32609,
- 32678,
- 32727,
- 32757,
- 32767
- };
- static int sintblf[64]={
- 0,
- 12,
- 25,
- 37,
- 50,
- 62,
- 75,
- 87,
- 100,
- 113,
- 125,
- 138,
- 150,
- 163,
- 175,
- 188,
- 201,
- 213,
- 226,
- 238,
- 251,
- 263,
- 276,
- 289,
- 301,
- 314,
- 326,
- 339,
- 351,
- 364,
- 376,
- 389,
- 402,
- 414,
- 427,
- 439,
- 452,
- 464,
- 477,
- 490,
- 502,
- 515,
- 527,
- 540,
- 552,
- 565,
- 578,
- 590,
- 603,
- 615,
- 628,
- 640,
- 653,
- 665,
- 678,
- 691,
- 703,
- 716,
- 728,
- 741,
- 753,
- 766,
- 779,
- 791
- };
- static int phasein=0,phaseout=0,freqin=2048,freqout,sigcnt=0,delaypt=0;
- int mask,maskl,delmask;
- static long hilb26[13]={ -2332,6801,7121,5551,3165,-8266,11591,-1720,-5417,
- 17107,-8036,9810,25949};
- int xn[26],qn,xhn[2][32],bit;
- struct ctone {
- int sine,cosine
- } iandq;
- main (argc,argv)
- int argc;
- char *argv[];
- {
- void sincos();
- FILE *f1;
- int i,*store,j,k,xnpt1,xnpt2;
- char *malloc();
- long tmp;
- f1=fopen("d:tone.pcm","wb");
- store=(int *)malloc(0x8000);
- srand(1);
- mask = (1<<14)-1;
- maskl = (1<<6)-1;
- bit=1;
- for (j=0;j<6;j++){
- printf("%d",j);
- for (i=0;i<16384;i++) {
- sincos(freqin,&phasein);
- if (sigcnt++==24){
- if (rand()>16384) bit=-1;
- else bit=1;
- sigcnt=0;
- }
- xn[delaypt]=iandq.sine*bit;
- tmp=0;
- for (k=0;k<13;k++) {
- xnpt1=k+delaypt;
- xnpt2=25-k+delaypt;
- if (xnpt1>25) xnpt1 -= 26;
- if (xnpt2>25) xnpt2 -= 26;
- tmp += hilb26[k]*(xn[xnpt1]-xn[xnpt2]);
- }
- delaypt -= 1;
- if (delaypt <0 ) delaypt = 25;
- qn = (iandq.sine*bit);
- *(store+i)=(qn>>5)+0x800;
- }
- fwrite((char *)store,2,16384,f1);
- }
- fclose(f1);
- }
- void sincos(freq,phase)
- int freq,*phase;
- {
- long cosx,sinx;
- int wkph,mpc,mps,coph,fiph;
- wkph = *phase;
- mps=1;
- mpc=1;
- a: switch((wkph>>12)) {
- case 0: break;
- case 1:{
- wkph = (1<<13)-wkph;
- mpc = -1;
- break;
- }
- default: {
- wkph -= (1<<13);
- mps = -1;
- goto a;
- }
- }
- coph = wkph>>6;
- fiph = wkph&maskl;
- sinx = sintblc[coph];
- cosx = sintblc[((1<<6)-coph)];
- iandq.sine = ((sinx<<16) + sintblf[fiph]*cosx)>>16;
- iandq.sine *= mps;
- wkph = (1<<12) - wkph;
- coph = wkph>>6;
- fiph = wkph&maskl;
- sinx = sintblc[coph];
- cosx = sintblc[((1<<6)-coph)];
- iandq.cosine = ((sinx<<16) + sintblf[fiph]*cosx)>>16;
- iandq.cosine *= (mps*mpc);
- *phase += freq;
- *phase &= mask;
- }
-